package com.pdsu.graduation_design.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.pdsu.graduation_design.R;
import com.pdsu.graduation_design.domain.Commodity;
import com.squareup.picasso.Picasso;

import java.util.List;

public class MainSearchListViewAdapter extends BaseAdapter {

    private Context context;
    private List<Commodity> commodities;

    private ImageView imageView;
    private TextView cname,cprice,cmessage,username;
    public MainSearchListViewAdapter(Context context, List<Commodity> commodities) {
        this.context = context;
        this.commodities = commodities;
    }

    @Override
    public int getCount() {
        return commodities.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view=View.inflate(context, R.layout.activity_main_grid_view_item_detail_item,null);

        imageView=view.findViewById(R.id.activity_main_listview_item_image);
        cname= view.findViewById(R.id.activity_main_listview_item_title);
        cprice=view.findViewById(R.id.activity_main_listview_item_price);
        cmessage=view.findViewById(R.id.activity_main_listview_item_message);
        username=view.findViewById(R.id.activity_main_listview_item_username_tv);

        cname.setText(commodities.get(position).getCname());
        cprice.setText(commodities.get(position).getPrice()+"");
        cmessage.setText(commodities.get(position).getCmessage());
        username.setText(commodities.get(position).getUsername());
        Picasso.with(context).load(commodities.get(position).getImage()).into(imageView);

        return view;
    }
}
